
export function speak(text,language) {
  if (/^\s*$/.test(text)){return;}
  const speech = new SpeechSynthesisUtterance(text);
  speech.lang = "zh-CN";//语音的语言。可以使用BCP 47语言标记来指定语言。例如，英语为"en-US"，中文为"zh-CN"
  speech.volume = 1;//语音的音量。取值范围为0到1，默认值为1
  speech.rate = 1;//语音的播放速率。取值范围为0.1到10，默认值为1。1表示正常速率，小于1表示较慢的速率，大于1表示较快的速率
  speech.pitch = 1;//语音的音调。取值范围为0到2，默认值为1。1表示正常音调，小于1表示较低的音调，大于1表示较高的音调
  //语音的发音人（声音）。可以通过SpeechSynthesis.getVoices()来获取可用的声音列表，并根据需要选择适合的声音。
  // 例如，可以使用speechSynthesis.getVoices().find(voice => voice.name === 'Google 普通话（中国）')来选择中文普通话的发音人。
  //以上是一些常用的属性，您可以根据具体需求进行配置
  if (/^\s*$/.test(language) === false){
    speech.voice = speechSynthesis.getVoices().find(voice => voice.name === language);
  }
  speechSynthesis.speak(speech);
}

/**
 * 获取语音包
 */
export function getLanguagePackage(){
  return [
    { name: '机械女', language: 'Microsoft Huihui - Chinese (Simplified, PRC)'},
    { name: '机械女2', language: 'Microsoft Kangkang - Chinese (Simplified, PRC)'},
    { name: '机械女3', language: 'liaoning-Microsoft Xiaobei Online (Natural) - Chinese (Northeastern Mandarin)'},
    { name: '机械女4', language: 'Microsoft Yaoyao - Chinese (Simplified, PRC)'},
    { name: '机械女5', language: 'Microsoft HiuGaai Online (Natural) - Chinese (Cantonese Traditio'},
    { name: '机械女6', language: 'shaanxi-Microsoft Xiaoni Online (Natural) - Chinese (Zhongyuan Mandarin Shaanxi)'},
    { name: '粤语-香港', language: 'Microsoft HiuMaan Online (Natural) - Chinese (Hong Kong)'},
    { name: '粤语-香港2', language: 'Microsoft WanLung Online (Natural) - Chinese (Hong Kong)'},
    { name: '粤语', language: 'Microsoft HiuGaai Online (Natural) - Chinese (Cantonese Traditional)'},
    { name: '甜美', language: 'Microsoft Xiaoxiao Online (Natural) - Chinese (Mainland)'},
    { name: '萝莉', language: 'Microsoft Xiaoyi Online (Natural) - Chinese (Mainland)'},
    { name: '男中音', language: 'Microsoft Yunjian Online (Natural) - Chinese (Mainland)'},
    { name: '正太', language: 'Microsoft Yunxi Online (Natural) - Chinese (Mainland)'},
    { name: '小男孩', language: 'Microsoft Yunxia Online (Natural) - Chinese (Mainland)'},
    { name: '男磁性', language: 'Microsoft Yunyang Online (Natural) - Chinese (Mainland)'},
    { name: '台湾女', language: 'Microsoft HsiaoChen Online (Natural) - Chinese (Taiwan)'},
    { name: '台湾男', language: 'Microsoft YunJhe Online (Natural) - Chinese (Taiwan)'},
    { name: '台湾女（慢）', language: 'Microsoft HsiaoYu Online (Natural) - Chinese (Taiwanese Mandarin)'},
  ];
}
